
   //nav
   function showMenu(){
       const uldom = document.querySelector("#menuList");
       uldom.classList.toggle("open");
   }

   //tab页
   function show(type){
       let msDiv = document.querySelector(".message");
       let artDiv = document.querySelector(".article");
       let photoDiv = document.querySelector(".photo");

       if(type =="message"){
           msDiv.style.display = "block";
           artDiv.style.display = "none";
           photoDiv.style.display = "none";
       }
       if(type =="article"){
           msDiv.style.display = "none";
           artDiv.style.display = "block";
           photoDiv.style.display = "none";
       }
       if(type =="photo"){
           msDiv.style.display = "none";
           artDiv.style.display = "none";
           photoDiv.style.display = "block";
       }
   }

   //注册
   function reg(type){
       if(type == "in")
       {
           document.querySelector("#reg").style.display = "block";
           document.querySelector("#login").style.display = "none";
       }
       else if(type == "back")
       {
           document.querySelector("#reg").style.display = "none";
           document.querySelector("#login").style.display = "block";
       }

   }

   //校验
   function validate(type){
       let logName = document.querySelector("#logName").value;
       let logPassword = document.querySelector("#logPassword").value;
       let regName = document.querySelector("#regName").value;
       let regPassword = document.querySelector("#regPassword").value;
       let regConfirm = document.querySelector("#regConfirm").value;

       //登录
       if(type == "1")
       {
           if(logName == ""||logPassword ==""){
               alert("用户名或者密码不能为空！");
               return false;
           }
           return true;
       }
       //注册
       if(type == "2")
       {
           if(regName == ""|| regPassword ==""){
               alert("用户名或者密码不能为空！");
               return false;
           }
           if(regPassword === regConfirm)
           {
               return true;
           }
           else{
               alert("两次输入的密码不一致，请重新输入！");
               return false;
           }
       }


   }

   //文章校验
   function articleVali(type){
       let title;
       let body;
       let form;

        if("create" == type) {
            title = document.querySelector("#createTitle").value;
            body = document.querySelector("#createBody").value;
            form = document.querySelector("#create");
        }
        else{
            title = document.querySelector("#editTitle").value;
            body = document.querySelector("#editBody").value;
            form = document.querySelector("#update");
        }

       if(title == ""||body == "")
       {
           alert("主题或者内容不能为空！");
           return false;
       }
       else{
           if(textLeng(title) > 15)
           {
               alert("题目长度不能超过15！");
               return false
           }
           if(textLeng(body) > 30)
           {
               alert("内容长度不能超过30！");
               return false;
           }
       }
       form.submit();
       return true;
   }

   //兼容中文英文长度
   function textLeng(str){
       return str.replace(/[\u0391-\uFFE5]/g,"aa").length;
   }

   function del(){
       if(confirm("确定删除文章？")){
           return true;
       }
       else{
           return false;
       }
   }
